# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=keystone
pkgver=0.9.2
pkgrel=6
pkgdesc="Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings"
url="https://www.keystone-engine.org/"
arch="all !riscv64 !loongarch64" # weird cmake + autoconf hybrid system is weird and hates riscv
license="custom"
makedepends="cmake python3-dev py3-setuptools"
subpackages="$pkgname-dev $pkgname-python-pyc $pkgname-python"
source="$pkgname-$pkgver.tar.gz::https://github.com/keystone-engine/keystone/archive/$pkgver.tar.gz"

prepare() {
	default_prepare
	update_config_guess
}

build() {
	mkdir -p build-shared && cd build-shared
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=ON \
		-G "Unix Makefiles" ..
	cd ..
	make -C build-shared

	cd "$builddir"/bindings/python
	python3 setup.py build
}

package() {
	make -C build-shared DESTDIR="$pkgdir" install

	cd "$builddir"/bindings/python
	python3 setup.py install --skip-build --root="$pkgdir"
}

python() {
	pkgdesc="$pkgname python3 bindings"
	depends="python3 keystone"
	amove usr/lib/python3*
}

sha512sums="
5d4dd30410410bc7848e75a2e31e8ecef6241ad25e21963aa7a07bbea21d95b75e235c80573129014102684c9647710ace3c0776a8401844d7e4b45cab7bd04b  keystone-0.9.2.tar.gz
"
